
// 坐标轴最大值更新
function updateAxisMax(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].max = value !== '' ? parseFloat(value) : null;
    }
    return newOptions;
}

// 坐标轴最小值更新
function updateAxisMin(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].min = value !== '' ? parseFloat(value) : null;
    }
    return newOptions;
}

// 坐标轴位置更新
function updateAxisPosition(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].position = value;
    }
    return newOptions;
}

// 坐标轴偏移量更新
function updateAxisOffset(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].offset = parseInt(value, 10);
    }
    return newOptions;
}

// 坐标轴名称文本颜色更新
function updateAxisNameTextColor(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].nameTextStyle = {
            ...newOptions[`${axis}Axis`][0].nameTextStyle,
            color: value
        };
    }
    return newOptions;
}

// 坐标轴名称文本字体大小更新
function updateAxisNameTextFontSize(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].nameTextStyle = {
            ...newOptions[`${axis}Axis`][0].nameTextStyle,
            fontSize: parseInt(value, 10)
        };
    }
    return newOptions;
}

// 坐标轴名称文本字体粗细更新
function updateAxisNameTextFontWeight(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].nameTextStyle = {
            ...newOptions[`${axis}Axis`][0].nameTextStyle,
            fontWeight: value
        };
    }
    return newOptions;
}

// 坐标轴名称文本样式更新
function updateAxisNameTextStyle(axis, styleProp, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].nameTextStyle = {
            ...newOptions[`${axis}Axis`][0].nameTextStyle,
            [styleProp]: value
        };
    }
    return newOptions;
}

// 坐标轴标签颜色更新
function updateAxisLabelColor(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].axisLabel = {
            ...newOptions[`${axis}Axis`][0].axisLabel,
            color: value
        };
    }
    return newOptions;
}

// 坐标轴标签间隔更新
function updateAxisLabelInterval(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].axisLabel = {
            ...newOptions[`${axis}Axis`][0].axisLabel,
            interval: parseInt(value, 10)
        };
    }
    return newOptions;
}

// 坐标轴标签替换更新
function updateAxisLabelReplace(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].axisLabel = {
            ...newOptions[`${axis}Axis`][0].axisLabel,
            replace: value === 'true'
        };
    }
    return newOptions;
}

// 坐标轴标签最大字符数更新
function updateAxisLabelMaxChar(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].axisLabel = {
            ...newOptions[`${axis}Axis`][0].axisLabel,
            maxChar: parseInt(value, 10)
        };
    }
    return newOptions;
}

// 坐标轴标签旋转角度更新
function updateAxisLabelRotate(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].axisLabel = {
            ...newOptions[`${axis}Axis`][0].axisLabel,
            rotate: parseInt(value, 10)
        };
    }
    return newOptions;
}

// 坐标轴反向更新
function updateAxisInverse(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].inverse = value === 'true';
    }
    return newOptions;
}

// 坐标轴线显示状态更新
function updateAxisLineVisibility(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].axisLine = {
            ...newOptions[`${axis}Axis`][0].axisLine,
            show: value === 'true'
        };
    }
    return newOptions;
}

// 坐标轴线样式更新
function updateAxisLineStyle(axis, styleProp, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].axisLine = {
            ...newOptions[`${axis}Axis`][0].axisLine,
            lineStyle: {
                ...newOptions[`${axis}Axis`][0].axisLine?.lineStyle,
                [styleProp]: styleProp === 'width' ? parseInt(value, 10) : value
            }
        };
    }
    return newOptions;
}

// 坐标轴分割线样式更新
function updateAxisSplitLineStyle(axis, styleProp, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].splitLine = {
            ...newOptions[`${axis}Axis`][0].splitLine,
            lineStyle: {
                ...newOptions[`${axis}Axis`][0].splitLine?.lineStyle,
                [styleProp]: styleProp === 'width' ? parseInt(value, 10) : value
            }
        };
    }
    return newOptions;
}

// 坐标轴缩放设置更新
function updateAxisScale(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].scale = value === 'true';
    }
    return newOptions;
}

// 坐标轴显示状态更新
function updateAxisVisibility(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].show = value === 'true';
    }
    return newOptions;
}

// 坐标轴名称更新
function updateAxisName(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].name = value;
    }
    return newOptions;
}

// 坐标轴名称样式更新
function updateAxisNameStyle(axis, styleProp, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].nameTextStyle = {
            ...newOptions[`${axis}Axis`][0].nameTextStyle,
            [styleProp]: value
        };
    }
    return newOptions;
}

// 坐标轴分割线显示状态更新
function updateAxisSplitLineShow(axis, value, options) {
    const newOptions = { ...options };
    if (newOptions[`${axis}Axis`]) {
        newOptions[`${axis}Axis`][0].splitLine = {
            ...newOptions[`${axis}Axis`][0].splitLine,
            show: value === 'true'
        };
    }
    return newOptions;
}
/**
 * 更新坐标轴标签可见性
 * @param {string} axisType - 坐标轴类型（'x' 或 'y'）
 * @param {string|boolean} value - 可见性值（'true'/'false' 或 true/false）
 * @param {Object} currentOptions - 当前图表配置选项
 * @returns {Object} 更新后的图表配置选项
 */
function updateAxisLabelVisibility(axisType, value, currentOptions) {
    // 创建配置副本，避免直接修改原对象
    const newOptions = { ...currentOptions };
    const axisKey = `${axisType}Axis`;

    if (newOptions[axisKey]) {
        // 确保坐标轴数组和配置对象存在
        newOptions[axisKey] = [...newOptions[axisKey]];
        newOptions[axisKey][0] = { ...newOptions[axisKey][0] };
        newOptions[axisKey][0].axisLabel = {
            ...newOptions[axisKey][0].axisLabel
        };

        // 处理字符串形式的布尔值和实际布尔值
        newOptions[axisKey][0].axisLabel.show = value === 'true' || value === true;
    } else {
        console.warn(`坐标轴 ${axisType} 不存在，无法更新标签显示状态`);
    }

    // 只返回更新后的配置，由调用方处理setOption
    return newOptions;
}
/**
 * 更新X轴/Y轴的标签数值格式
 * @param {string} axis - 轴类型，'x' 或 'y'
 * @param {string} value - 格式化字符串（如 '{value}%'、'{value:.2f}'）
 * @param {Object} options - 当前图表配置项
 * @returns {Object} 更新后的配置项
 */
function updateAxisLabelFormatter(axis, value, options) {
    const newOptions = { ...options }; // 复制原有配置，避免直接修改
    const axisKey = `${axis}Axis`; // 拼接轴键名（xAxis/yAxis）

    // 检查轴配置是否存在，存在则更新axisLabel.formatter
    if (newOptions[axisKey]) {
        // 处理轴配置为数组的情况（ECharts中可能存在多轴）
        newOptions[axisKey] = newOptions[axisKey].map(axisItem => ({
            ...axisItem,
            axisLabel: {
                ...axisItem.axisLabel, // 保留原有其他轴标签配置
                formatter: value // 更新格式化规则
            }
        }));
    }

    return newOptions;
}